dist: $(CONFIG_MAKE)
	rm -rf $(PACKAGE)-$(VERSION)
	mkdir $(PACKAGE)-$(VERSION)
	make pre-dist-hook distdir=$$distdir
	for dir in $(call quote_each,$(SUBDIRS)); do \
		pkgdir=`pwd`/$(PACKAGE)-$(VERSION); \
		mkdir "$$pkgdir/$$dir" || true; \
		case $$dir in \
		.) make dist-local "distdir=$$pkgdir" || exit 1;; \
		*) (cd "$$dir"; make dist-local "distdir=$$pkgdir/$$dir") || exit 1;; \
		esac \
	done
	(make dist-local distdir=$(PACKAGE)-$(VERSION))
	make post-dist-hook "distsir=$$distdir"
	tar czvf $(PACKAGE)-$(VERSION).tar.gz $(PACKAGE)-$(VERSION)
	rm -rf $(PACKAGE)-$(VERSION)
	@echo "=========================================="
	@echo "$(PACKAGE)-$(VERSION) has been packaged > $(PACKAGE)-$(VERSION).tar.gz"
	@echo "=========================================="

distcheck: dist
	(mkdir test; cd test;  \
	tar xzvf ../$(PACKAGE)-$(VERSION).tar.gz; cd $(PACKAGE)-$(VERSION); \
	./configure --prefix=$$(cd `pwd`/..; pwd); \
	make && make install && make dist);
	rm -rf test
